Skip to main content

tsvImportFromFile

Type

command

Summary

Parse tabular data from a TSV file into an array

Syntax

tsvImportFromFile <pFile>,<pOptions>,<rArray>

Description

This command takes in a filename present in the current defaultFolder, computes the data based on optional parameters and returns it as an array.

The quoting rule determines how quotes are treated in the data to import. If it is none then quotes have no effect on parsing, and the data is just split based on the chosen delimiter. Otherwise quoted values can contain the delimiter itself as well as return characters.

When specifying the quoting-rule for TSV import, consider the following options:

  • "all": All fields are quoted
  • "minimal": Fields with special characters (like delimiter) have quotes
  • "none": Quotes have no effect on parsing

Parameters

NameTypeDescription

pFile

File Name

pOptions

An array of options to use when importing tsv. The keys are as follows:

  • "has-header-row": whether to treat the first row of data as column header names. Defaults to false.
  • "delimiter": character used to delimit values. Defaults to tab.
  • "quoting-rule": how to treat quoting in the target file; one of 'all', 'minimal', or 'none'.

rArray

Returns a nested array with data parsed from input file with format: { "headers": [ col1header, col2header,...], "data": [ [row1col1data, row1col2data, ...], [row2col1data, row2col2data, ...] ] }

Examples

local tFile
answer file "Select a tsv file" with type "TSV files|tsv|TSV"
put the result into tFile

local tArray
tsvImportFromFile \
tFile, \
{ "has-header-row": true }, \
tArray